<?php
class Data_Model_ChiTietLopHocMapper extends Data_Model_DataMapperAbstract
{
		protected static $_instance = null;
		// dung de phan trang
		private $_paginator = null;
		
		public function searchByMalophoc($id)
		{
			$db = $this->getDb();
			$selectCtlh = $db->select()
							->from('tbl_chitietlophoc')
							->join('tbl_lophoc','tbl_chitietlophoc.MaLop = tbl_lophoc.MaLop')
							->where('tbl_chitietlophoc.MaLop = ?',$id);
			$ctlhs = $db->fetchAll($selectCtlh);
			
			$chitietlophocArray = array();
			foreach($ctlhs as $ctlh)
			{
				$hinhthucthiMapper = Data_Model_HinhThucThiMapper::getInstance();
				$hinhthucthi = $hinhthucthiMapper->searchById($ctlh['MaHinhThuc']);
				$ctlh['tbl_hinhthucthi'] = $hinhthucthi;
				
			    $chitietlophocArray[] = $this->_populate($ctlh);
			}
			return $chitietlophocArray;
		}
	/* (non-PHPdoc)
	 * @see Data_Model_DataMapperAbstract::_insert()
	 */protected function _insert(Data_Model_DomainObjectAbstract $obj) {
		// TODO Auto-generated method stub
		$db = $this->getDb();
		$data = array(
				'MaHinhThuc' => $obj->getMahinhthuc(),
				'MaLop' => $obj->getMalop(),
		);
		$db->insert('tbl_chitietlophoc',$data);
		}
		

	/* (non-PHPdoc)
	 * @see Data_Model_DataMapperAbstract::_update()
	 */protected function _update(Data_Model_DomainObjectAbstract $obj) {
		// TODO Auto-generated method stub
		$db = $this->getDb();
		$data = array(
				'MaHinhThuc' => $obj->getMahinhthuc(),
				'MaLop' => $obj->getMalop()
		);
		$where = $db->quoteInto('ID = ?',$obj->getId());
		$db->update('tbl_chitietlophoc',$data,$where);
		}

	/* (non-PHPdoc)
	 * @see Data_Model_DataMapperAbstract::_populate()
	 */protected function _populate($data) {
		// TODO Auto-generated method stub
		$obj = new Data_Model_ChiTietLopHoc();
		$obj->setId($data['ID']);
		$obj->setMalop($data['MaLop']);
		$obj->setMahinhthuc($data['MaHinhThuc']);
		return $obj;
		}

		public function delete($id)
		{
			$db = $this->getDb();
			$where = $db->quoteInto('MaLop = ?',$id);
			$db->delete('tbl_chitietlophoc',$where);
		}
		
		// Goi chinh no
		
		public static function getInstance()
		{
			if(null === self::$_instance)
			{
				self::$_instance = new self();
			}
			return self::$_instance;
		}	
}